package Thread;

import java.util.concurrent.Semaphore;

public class Demo30 {
    public static void main(String[] args) throws InterruptedException {
        //可用资源的个数，计数器的初始值
        Semaphore semaphore = new Semaphore(3);
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.release();
        System.out.println("释放一个资源");
        semaphore.release();
        System.out.println("释放一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");

    }
}
